    //
//  addWatchList.m
//  iStock Global
//
//  Created by Andy on 2010/11/15.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "addWatchList.h"
#import "AppDelegate.h"
#import "SplitViewDelegate.h"

@implementation addWatchList
@synthesize delegate;
@synthesize addw;
@synthesize delegate_UIPopoverController;
@synthesize AppleDeglate;
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

 
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	UIView *mainview;
	mainview=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
	self.view=mainview;
    [mainview release];
    
	self.view.backgroundColor=[UIColor  lightGrayColor];	
	
	UINavigationBar *nav;
	
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        
        if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ){
            //垂直
            
            nav = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 600.0f, 48.0f)];	        
            
            
        }
        else{
            //水平
            
            
             nav = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 600.0f, 48.0f)];            
            
            
            
            
        }
        
        
        
    }
    else{
        
        nav = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];	        
            
    }    
    
    
  
	
	UIBarButtonItem *barButton ;
	barButton = [[UIBarButtonItem alloc] initWithTitle: NSLocalizedString(@"Done",@"完成")  style:UIBarButtonItemStylePlain target:self action:@selector(addSave)];
	UINavigationItem *item;
	item = [[UINavigationItem alloc] initWithTitle: NSLocalizedString(@"Add Watch List Group",@"新增自選股 群組")  ];
	[item setRightBarButtonItem: barButton];
	[nav pushNavigationItem:item animated:NO];
	[item release];
	[mainview addSubview:nav];	
	[nav release];
	
    
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        
        if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
            //垂直
            
            //增加輸入自選股欄位
            addw=[[UITextField alloc] initWithFrame:CGRectMake(80, 230, 350, 30)];	        
            
            
        }
        else{
            //水平
            
            
            //增加輸入自選股欄位
            addw=[[UITextField alloc] initWithFrame:CGRectMake(30, 130, 250, 30)];            
            
            
        }
        
        
        
    }
    else{
        
        //增加輸入自選股欄位
        addw=[[UITextField alloc] initWithFrame:CGRectMake(30, 130, 250, 30)];	        
        
    }    
    
    
    
    
    
	addw.borderStyle=UITextBorderStyleRoundedRect;
	addw.backgroundColor=[UIColor clearColor];
	addw.delegate=self;
	addw.clearButtonMode=UITextFieldViewModeAlways;
	addw.placeholder=NSLocalizedString(@"Input Group Name",@"Input Group Name") ;
	[addw becomeFirstResponder]; //啓動時喚起鍵盤	
	addw.returnKeyType=UIReturnKeyJoin;
	[mainview addSubview:addw];
	
	
	
}
-(void)addSave{
	[self.delegate addWatchListControllerDidFinish:self];
    [delegate_UIPopoverController dismissPopoverAnimated:YES]; 
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        
        if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
            //垂直
            //將本身消失
           
            
            //恢復原本的主圖
            [[(AppDelegate * )AppleDeglate Master_popController] presentPopoverFromBarButtonItem: 
             [(SplitViewDelegate *)[(AppDelegate * )AppleDeglate splitViewDelegate] showmasterUIBarButtonItem]  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
            
            
        }
        else{
            //水平
            
             
            
            
            
        }
        
        
        
    }
    else{
        
        
    }    
    
    
    
    
    
    
	 
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
	[self addSave];
	return NO;
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
